/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecom.beans.cart;

import ecom.beans.dish.*;


import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

/**
 *
 * @author Tian
 */


@NamedQueries({
  @NamedQuery(name = "findAllItems", query = "SELECT item FROM ItemEntity item"),
  
  @NamedQuery(name = "findItemById", query = "SELECT item FROM ItemEntity item WHERE item.id = :id"),
  
  @NamedQuery(name = "findItemInCart", query = "SELECT item FROM ItemEntity item WHERE item.itemCart.id = :cartId AND item.itemProduct.id = :productId"),
  
  @NamedQuery(name = "findAllItemsByCartId", query = "SELECT item FROM ItemEntity item WHERE item.itemCart.id = :cartId")
 })

@Entity
public class ItemEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToOne
    private DishEntity itemProduct;
    
    private int itemQuantity;

    @ManyToOne
    private CartEntity itemCart;

    public CartEntity getItemCart() {
        return itemCart;
    }

    public void setItemCart(CartEntity itemCart) {
        this.itemCart = itemCart;
    }

    /*************************************************/
    
    public int getItemQuantity() {
        return itemQuantity;
    }

    public void setItemQuantity(int itemQuantity) {
        this.itemQuantity = itemQuantity;
    }
    

    public DishEntity getItemProduct() {
        return itemProduct;
    }

    public void setItemProduct(DishEntity itemProduct) {
        this.itemProduct = itemProduct;
    }
 
    public void setId(Long id) {
        this.id = id;
    }

    
    public Long getId() {
        return id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ItemEntity)) {
            return false;
        }
        ItemEntity other = (ItemEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ejb.cart.ItemEntity[id=" + id + "]";
    }

}
